ResourceCurd = Ext.extend(Ext.TabPanel, {
	constructor : function(config) {
		Ext.apply(this, {
			title : '系统资源管理',
			closable : true,
			//tabPosition : 'bottom',
			renderTo : Ext.getBody(),
			activeTab : 0,
			border : false,
			items : [ new MenuResourceCurd(),new ControlResourceCurd()]
		});
		ResourceCurd.superclass.constructor.call(this, config);
	}
});
/*
 * 控制类权限资源管理
 */
ControlResourceCurd = Ext.extend(RockyTreeCurd,{
	constructor : function(config) {
		this.root = new Ext.tree.AsyncTreeNode( {
			id : "root",
			text : "root",
			loader : new RockyCurd.TreeLoader( {
				dataUrl : "genControlResourceTree.action",
				expanded : true,
				nodeMeta : {
					id : 'id',
					text : 'name'
				}
			})
		});
		Ext.apply( this,{
			title : "控制类资源",
			disabled :true,
			tbar : ['   ', {
				text : '生成控制类资源',
				pressed : false,
				disabled :true,
				handler : this.createControlResource,
				scope : this
			}, new Ext.Toolbar.Fill(), '   '],		
			region : 'west',
			border : false,			
			split : true,
			width : 400,
			minSize : 275,
			maxSize : 500,
			collapsible : true,
			layout : 'accordion',
			layoutConfig : {
				animate : true
			},
			autoScroll : true,
			animate : true,
			border : false,
			rootVisible : false,
			root : this.root,
			listeners : {
				'show' : function() {
					this.root.expand(true);
				},
				scope : this
			}
		});
		ControlResourceCurd.superclass.constructor.call(this,config);
	},
	createControlResource:function(){
		Ext.Ajax.request( {
			url : 'createAll.action',
			params : {
				'from':'admin'
			},
			method : 'POST',
			success : function(response) {				
				var r = Ext.decode(response.responseText);
				if (!r.success) {
					Ext.Msg.alert("提示信息","失败，由以下原因所致：<br/>"+ (r.errors? r.errors: "未知原因"));
				} else {
					Ext.Msg.alert("提示信息", "保存成功!");
					this.refresh();
				}
			},
			failure:function(Optional){
				//Ext.getBody().unmask();
				Ext.Msg.alert("提示信息", "连接服务器失败!");								 
			}, 
			scope : this
		});
	}

});
/*
 * 菜单类权限资源管理
 */
MenuResourceCurd  = Ext.extend(RockyTreeCurd,{
	constructor : function(config) {
		this.root = new Ext.tree.AsyncTreeNode( {
			id : "root",
			text : "root",
			"isWebnewscat" : "false",
			listeners : {
				'click' : function(node, event) {
					node.expand(true);
				}
			},
			loader : new RockyCurd.TreeLoader( {
				dataUrl : "genResourceTree.action?from=menu",
				expanded : true,
				nodeMeta : {
					id : 'id',
					text : 'name'
				}
			})
		});		
		Ext.apply(this,{
			title : "菜单类资源",
			tbar : ['   ', {
				text : '生成菜单类资源',
				pressed : false,
				handler : this.createMenuResource,
				scope : this
			}, new Ext.Toolbar.Fill(), '   '],				
			region : 'west',
			border : false,		
			split : true,
			width : 400,
			minSize : 275,
			maxSize : 500,
			collapsible : true,
			layout : 'accordion',
			layoutConfig : {
				animate : true
			},
			autoScroll : true,
			animate : true,
			border : false,
			rootVisible : false,
			root : this.root,
			listeners : {
				'show' : function() {
					this.root.expand(true);
				},
				scope : this
			}
		});
		MenuResourceCurd.superclass.constructor.call(this,config);
	},
	createMenuResource:function(){
		Ext.Ajax.request( {
			url : 'createResourceMenu.action',
			params : {
				'from':'admin'
			},
			method : 'POST',
			success : function(response) {
				var r = Ext.decode(response.responseText);
				if (!r.success) {
					Ext.Msg.alert("提示信息","失败，由以下原因所致：<br/>"+ (r.errors? r.errors: "未知原因"));
				} else {
					Ext.Msg.alert("提示信息", "成功生成系统菜单!");
					this.refresh();
				}
			},
			failure:function(Optional){
				Ext.Msg.alert("提示信息", "连接服务器失败!");								 
			}, 
			scope : this
		});
	}



});